<template>
	<!-- 处方上传 -->
	<view class="container">
		<cu-custom :bgColor="'bg-' + theme.backgroundColor" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">处方上传</block>
		</cu-custom>
		<view class="thk-lc">
			<image src="../../../static/images/cflc.png"></image>
		</view>

		<view class="header radius shadow-warp">
			<view class="flex header-title justify-between">
				<view class="flex-twice pres-title">
					<text class>上传处方</text>
				</view>
			</view>

			<view class="wrapper-list bg-white radius">
				<scroll-view class="scroll-view_x" scroll-x style="width: auto; overflow: hidden">
					<view v-if="uploadImgUrl" class="pres-image">
						<view class="cuIcon-close cloes" @tap="delImg"></view>
						<image class :src="uploadImgUrl" mode="scaleToFill" @tap="previewImg"></image>
					</view>
					<view class="pres-image" @tap="upload" v-if="!uploadImgUrl">
						<image class src="../../../static/images/camera.png"></image>
					</view>
				</scroll-view>
			</view>
		</view>
		<view class="main radius shadow-warp">
			<view class="cu-form-group text-right">
				<view class="title">用药人</view>
				<input placeholder="请输入用药人姓名" type="text" @input="setBuyname" />
			</view>
			<view class="cu-form-group text-right arrow">
				<view class="title">性别</view>
				<picker :range="genderList" @change="genderChange">
					<text class="picker">{{ gender || "请选择" }}</text>
				</picker>
			</view>
			<view class="cu-form-group text-right">
				<view class="title">处方付数</view>
				<input placeholder="请输入处方付数" type="number" @input="selectNum" name="input" />
			</view>
			<view class="cu-form-group">
				<view class="title">是否代煎</view>
				<switch :checked="djFlag" class="green" @change="isdj"></switch>
			</view>
			<view class="cu-form-group">
				<view class="title">颗粒剂处方</view>
				<switch :checked="granules" class="green" @change="isGranules"></switch>
			</view>
			<!-- <view class="cu-form-group">
				<view class="title">颗粒剂处方</view>
				<switch :checked="tjtype === 1" class="green" @change="isklj"></switch>
			</view> -->
		</view>
		<view class="main radius shadow-warp">
			<view class="address-btn flex">
				<view v-for="(item, index) in distributionList" :key="index" :class="
            'btn-item flex-sub text-center ' +
            (transType == item.expressId ? 'bg-'+theme.backgroundColor : '')
          ">
					<view @tap="btnClick(item)">
						{{ item.name }}
					</view>
				</view>
			</view>
			<view class="line-address">
				<view class="cuIcon-location"></view>
				<view class="address" @tap="jumpToAddressList" v-if="userAddress.id != '' && transType != 2">
					<text class>{{ userAddress.provinceName }}</text>
					<text class>{{ userAddress.cityName }}</text>
					<text class>{{ userAddress.countyName }}</text>
					<text v-if="userAddress.address">{{ userAddress.address }}</text>
					<text class>{{ userAddress.detailInfo }}</text>
					<text class>{{ userAddress.userName }}</text>
					<text class>{{ userAddress.telNum }}</text>
				</view>
				<view class="address" v-if="transType == 2" @tap="jumpToAddressList(2)">
					<text>{{addressObj.address||'请选择店铺'}}</text>
				</view>
				<view class="addAddres" v-if="userAddress.id == '' && transType != 2" @tap="jumpToAddressList">
					请添加收货地址
				</view>
				<view class="cuIcon-right"></view>
			</view>
		</view>
		<view class="main">
			<navigator class="solid-bottom" hover-class="none" url="/pages_grid/pages/users/order-invoice/index">
				<view class="recipe solid-bottom">
					<view class="recipe_l">
						<view class="">发票</view>
					</view>
					<view v-if="!invoiceFlag" class="flex">
						<view style="margin-right: 10rpx" class="">不需要开发票</view>
						<text class="cuIcon-right"></text>
					</view>
					<view v-if="invoiceFlag" style="margin-right: 10rpx" class="flex">
						<view class="">{{ invoiceData[0].rise }}</view>
						<view class="">{{
              invoiceData[0].tax == null ? "" : invoiceData[0].tax
            }}</view>
						<text class="cuIcon-right"></text>
					</view>
				</view>
			</navigator>
			<form>
				<view class="cu-form-group align-start">
					<view class="title">备注</view>
					<textarea maxlength="-1" @input="memoInput" :value="memo" placeholder="请输入您的备注信息"></textarea>
				</view>
			</form>
		</view>
		<view style="height: 60px" class="safe"></view>
		<view class="bg-white padding-lr-sm flex flex-direction fixed safe">
			<button class="cu-btn margin-tb-sm lg" :class="'bg-' + theme.backgroundColor" @tap="wxgetSnowflake"
				:loading="loading" :disabled="loading">
				提交
			</button>
		</view>
		<!-- 提示图片上传成功 -->
		<view :class="'cu-modal ' + (successTip ? 'show' : '')">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content text-black">提示</view>
					<view class="action" @tap="successTipHide">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xl">您的处方已经上传成功,请等待审核！</view>
				<view class="cu-bar bg-white justify-end">
					<view class="action">
						<button class="cu-btn bg-green margin-left" @tap="successTipHide">
							确定
						</button>
					</view>
				</view>
			</view>
		</view>
		<!-- 提示删除图片 -->
		<view :class="'cu-modal ' + (showTip ? 'show' : '')">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content text-black">提示</view>
					<view class="action" @tap="showTipHide">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xl">您确定删除该处方的图片吗？</view>
				<view class="cu-bar bg-white justify-end">
					<view class="action">
						<button class="cu-btn line-green text-green" @tap="showTipHide">
							取消
						</button>
						<button class="cu-btn bg-green margin-left" @tap="deleteImg">
							确定
						</button>
					</view>
				</view>
			</view>
		</view>
		<!-- <user-auth id="userAuth"></user-auth> -->
	</view>
</template>

<script>
	// import Poster from 'components/wxa-plugin-canvas/poster/poster';
	// import { urlToHttpUrl } from 'public/wxParse/wxDiscode';
	const {
		base64src
	} = require("@/utils/base64src.js");
	const app = getApp();
	import __config from "@/config/env";
	import util from "@/utils/util";
	// import userAuth from "../../../components/user-auth/index";
	// import vanField from "@/miniprogram_npm/@vant/weapp/field/index";
	// import vanCellGroup from "@/miniprogram_npm/@vant/weapp/cell/index";
	// import goodsSku from "../../../components/goods-sku/index";
	import api from "@/utils/api";
	import baseRade from "@/components/base-rade/index";
	import poster from "@/components/wxa-plugin-canvas/poster/index";
	// import couponInfo from "../../../components/coupon-info/index";

	export default {
		components: {
			// userAuth,
			//    vanField,
			// vanCellGroup,
			// goodsSku,
			baseRade,
			poster,
			// couponInfo
		},
		data() {
			return {
				//是否是颗粒剂
				addressObj: {
					address: '',
					id: ''
				},
				granules: false,
				CustomBar: this.CustomBar,
				theme: app.globalData.theme, //全局颜色变量
				loading: false,
				userInfo: null,
				showAddr: true,
				uploaderList: [],
				uploaderListH5: [],
				imgArr: [],
				// 真正上传图片的URL
				page: {
					searchCount: false,
					current: 1,
					size: 10,
					ascs: "",
					//升序字段
					descs: "",
				},
				userAddress: {
					telNum: "",
					id: "",
					provinceName: "",
					cityName: "",
					countyName: "",
					address: "",
					detailInfo: "",
				},
				countPic: 9,
				//上传图片最大数量
				imageCode: null,
				//后台返回图片的id，每次上传图片需要携带
				showImgUrl: "",
				//路径拼接，一般上传返回的都是文件名，
				uploadImgUrl: "",
				//图片的上传的路径
				nums: [
					"0",
					"1",
					"2",
					"3",
					"4",
					"5",
					"6",
					"7",
					"8",
					"9",
					"10",
					"11",
					"12",
					"13",
					"14",
					"15",
					"16",
					"17",
					"18",
					"19",
					"20",
					"21",
					"22",
					"23",
					"24",
					"25",
					"26",
					"27",
					"28",
					"29",
					"30",
					"31",
					"32",
					"33",
					"34",
					"35",
					"36",
					"37",
					"38",
					"39",
					"40",
				],
				buyerCount: 0,
				//处方付数
				buyerIsdj: 1,
				//是否代煎标志
				tjtype: "", //是否颗粒剂
				djFlag: true,
				//代煎标志
				buyerIsjg: 0,
				//是否加工
				transType: 1,
				//取货方式
				buyerName: null,
				//购买人姓名
				memo: "",
				//备注
				isInvoice: 0,
				//是否开票
				isInvoiceFlag: false,
				//是否开票标志
				title: "",
				// 发票抬头
				identcode: "",
				//税号
				titleActive: false,
				isClause: false,
				// postUrl: 'https://btsyd.com/btsnewretail/btsyd/api/ma',
				// postUrl: 'http://192.168.123.87:9999/mallapi/api/ma',
				shareShow: "",
				goodsList: [],
				pflag: true,
				custServiceFlag: false,
				showTip: false,
				imgIndex: null,
				//要删除的图片下标
				successTip: false,
				distributionList: [{
						name: "自取",
						expressId: 2,
					},
					{
						name: "快递",
						expressId: 1,
					},
					// {
					//   name: "当日达",
					//   expressId: 3,
					// },
				],
				showInvoice: false,
				posterUrl: "",
				posterShow: false,
				posterConfig: "",
				invoiceData: {}, //发票信息
				invoiceFlag: false,
				adddressList: ["北京市丰台区西营街1号院通用时代中心25楼"],
				genderList: ["男", "女"],
				gender: "",
				isPrescription: null,
				isOpen: null,
			};
		},
		props: {},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			console.log("uploadOptions", options);
			// console.log(userInfo)
			let referee;
			if (options.scene) {
				//接受二维码中参数
				let scene = decodeURIComponent(options.scene);
				if (scene) {
					referee = scene;
				}
			} else if (options.referee) {
				referee = options.referee;
			}

			var that = this;
			app.initPage().then((res) => {
				that.userInfoGet();
				if (referee) {
					let params = {
						referee: referee,
						wxUseropenId: uni.getStorageSync("user_info").wxUseropenId,
					};
					that.bindSpread(params);
				}
				that.getDefaultAddress();
			});
		},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			//查询微信用户信息
			// this.wxUserGet();
		},
		onShareAppMessage: function() {
			let title = "通用药店";
			let path =
				"pages_grid/pages/prescription-upload/photo-upload/index?referee=" +
				uni.getStorageSync("user_info").refereeId || "";
			console.log(`path`, path);
			return {
				title: title,
				path: path,
				success: function(res) {
					if (res.errMsg == "shareAppMessage:ok") {
						console.log(res.errMsg);
					}
				},
				fail: function(res) {
					// 转发失败
				},
			};
		},
		methods: {
			getUserzeropay() {
				//查看客户是否为0元付款\
				let id = this.userInfo.id;
				api.getUserzeropay(id).then((res) => {
					console.log(res);
					if (res.data) {
						this.isPrescription = res.data.isPrescription;
						this.isOpen = res.data.isOpen;
						this.transType = 2;
					}
				});
			},
			genderChange(e) {
				let index = Number(e.detail.value);
				this.gender = this.genderList[index];
			},
			setInvoice(obj, obk) {
				if (obj == 0) {
					this.invoiceData = obk;
					this.invoiceFlag = true;
				} else {
					this.invoiceFlag = false;
				}
			},
			bindSpread(params) {
				//绑定分用人
				console.log(`处方上传推荐人绑定参数`, params);
				api.bindSpread(params).then((res) => {
					console.log(`处方上传推荐人绑定接口返回参数`, res.data);
				});
			},
			getDistribution(id) {
				//查询配送方式
				api.getDistribution(id).then((res) => {
					console.log(res);
					let distributionList = res.data;
					if (distributionList.length > 0) {
						let transType = distributionList[1].expressId;
						this.distributionList = distributionList;
						this.transType = transType;
					}
				});
			},
			hideModal() {
				this.custServiceFlag = false;
				// this.setData({
				// 	custServiceFlag: false
				// });
			},
			showPres() {
				if (app.globalData.wxUser.tabBarFlag == 0) {
					this.custServiceFlag = true;
					// this.setData({
					// 	custServiceFlag: true
					// });
				} else {
					this.custServiceFlag = false;
					// this.setData({
					// 	custServiceFlag: false
					// });
				}
			},
			wxUserGet() {
				api.wxUserGet().then((res) => {
					this.userInfo = res.data;
					console.log(res);
					// this.setData({
					// 	userInfo: res.data
					// });
				});
			},

			setUserAddress(e) {
				console.log(`12345`, e);
				this.userAddress = e;
			},
			//获取商城用户信息
			userInfoGet() {
				api.userInfoGet().then((res) => {
					this.userInfo = res.data;
					// this.getUserzeropay(); //查看是否为0元付款客户
				});
			},
			selectClause() {
				if (this.isClause == true) {
					this.isClause = false;
					this.titleActive = false;
					// this.setData({
					// 	isClause: false,
					// 	titleActive: false
					// });
				} else {
					this.isClause = true;
					this.titleActive = true;
					// this.setData({
					// 	isClause: true,
					// 	titleActive: true
					// });
				}
			},
			setBuyname(e) {
				this.buyerName = e.detail.value;
			},
			isklj(e) {
				//是否颗粒剂
				let flag = e.detail.value;
				this.tjtype = flag ? 1 : "";
			},
			isdj(e) {
				//是否代煎
				let flag = e.detail.value;
				if (flag) {
					this.djFlag = true;
					this.buyerIsdj = 1;
				} else {
					this.djFlag = false;
					this.buyerIsdj = 0;
				}
			},
			isGranules(e) {
				//是否代煎
				let flag = e.detail.value;
				if (flag) {
					this.granules = true;
					// this.buyerIsdj = 1
				} else {
					this.granules = false;
					// this.buyerIsdj = 0
				}
			},

			isjg(e) {
				//是否加工
				this.buyerIsjg = e.detail.value;
			},

			selectNum(e) {
				//选择处方付数
				this.buyerCount = e.detail.value;
			},

			btnClick(item) {
				this.transType = item.expressId;
			},

			selectInvoice(e) {
				//是否开发票
				let flag = e.detail.value;
				if (flag) {
					this.isInvoiceFlag = true;
					this.isInvoice = 1;
				} else {
					this.isInvoiceFlag = false;
					this.isInvoice = 0;
				}
			},

			memoInput(e) {
				//备注
				this.memo = e.detail.value;
			},
			delImg() {
				uni.showModal({
					title: "删除",
					content: "确认删除已上传的图片吗?",
					showCancel: true,
					success: ({
						confirm,
						cancel
					}) => {
						if (confirm) {
							this.uploadImgUrl = "";
						}
					},
				});
			},
			upload() {
				//选择需要上传的图片
				var that = this;
				uni.chooseImage({
					count: 1,
					sizeType: ["original", "compressed"],
					sourceType: ["album", "camera"],
					success: (res) => {
						console.log(res, "1111111111111111");
						this.uploadImg(res.tempFilePaths[0]);
						// uploadAvatar(res.)
						//   let tempFilePathsH5 = res;
						//   let ListH5 = [];
						//   ListH5.push(tempFilePathsH5);
						//   that.uploaderListH5 = that.uploaderListH5.concat(ListH5);
						//   const tempFilePaths = res.tempFilePaths;
						//   let uploaderList = that.uploaderList.concat(tempFilePaths);
						//   that.uploaderList = uploaderList;
					},
					fail: () => {},
					complete: () => {},
				});
			},
			uploadImg(filePath) {
				// 上传头像
				let _url = "/mallapi/file/upload";
				//#ifndef H5
				_url = __config.basePath + _url;
				//#endif
				let that = this;
				uni.showLoading({
					title: "上传中",
				});
				uni.uploadFile({
					header: {
						"client-type": "MA", //客户端类型小程序
						"app-id": uni.getAccountInfoSync().miniProgram.appId, //小程序appId
						"third-session": uni.getStorageSync("third_session") ?
							uni.getStorageSync("third_session") : "",
					},
					url: _url,
					filePath: filePath,
					name: "file",
					formData: {
						fileType: "image",
						dir: "headimg/",
					},
					success: (uploadFileRes) => {
						if (uploadFileRes.statusCode == "200") {
							that.uploadImgUrl = JSON.parse(uploadFileRes.data).link;
						} else {
							uni.showModal({
								title: "提示",
								content: "上传失败：" + uploadFileRes.data,
								success(res) {},
							});
						}
					},
					fail: (err) => {
						console.log(err);
					},
					complete: () => {
						uni.hideLoading();
					},
				});
			},

			showTipOpen(index) {
				this.showTip = true;
				this.imgIndex = index;
			},
			showTipHide() {
				this.showTip = false;
			},
			deleteImg(e) {
				//删除已选择的图片
				let imgIndex = this.imgIndex;
				let presImgs = this.uploaderList;
				presImgs.splice(imgIndex, 1);
				this.uploaderList = presImgs;
				this.showTip = false;
			},
			previewImg(e) {
				//图片上传
				//获取当前图片的下标
				// let index = e.currentTarget.dataset.index; //获取所有图片
				let imgs = [this.uploadImgUrl];
				uni.previewImage({
					current: imgs[0],
					urls: imgs,
				});
			},
			wxgetSnowflake() {
				if (!this.buyerName) {
					uni.showToast({
						title: "请输入用药人姓名",
						icon: "none",
						duration: 1500,
					});
				} else if (!this.gender) {
					uni.showToast({
						title: "请选择性别",
						icon: "none",
						duration: 1500,
					});
				} else if (!/^\d{1,}$/.test(this.buyerCount)) {
					uni.showToast({
						title: "处方付数请输入纯数字",
						icon: "none",
						duration: 1500,
					});
				} else if (this.buyerCount < 1) {
					uni.showToast({
						title: "请选择您的处方付数",
						icon: "none",
						duration: 1500,
					});
				} else if (this.buyerCount > 10000) {
					uni.showToast({
						title: "付数超出限制（10000付）",
						icon: "none",
						duration: 1500,
					});
				} else if (!this.uploadImgUrl) {
					uni.showToast({
						title: "请选择您要上传的图片",
						icon: "none",
						duration: 1500,
					});
				} else if (this.transType != 2 && !this.userAddress.id) {
					uni.showToast({
						title: "请选择您的邮寄地址",
						icon: "none",
						duration: 1500,
					});
				} else if (this.transType == 2 && !this.addressObj.id) {
					uni.showToast({
						title: "请选择自提店铺",
						icon: "none",
						duration: 1500,
					});
				} else {
					let para = {
						amount: this.buyerCount,
						deliveryWay: this.transType,
						isDj: this.djFlag ? "1" : "2",
						presType: this.granules ? "8" : "1",
						prescriptionUrl: this.uploadImgUrl,
						remark: this.memo,
						sex: this.gender == "男" ? "1" : "2",
						userName: this.buyerName,
						userAddressId: this.userAddress ? this.userAddress.id : "",
						userAddress: this.transType == 2 ? this.addressObj.address : '',
						shopId: this.transType == 2 ? this.addressObj.id : '',
						orderInvoiceId: this.invoiceData[0] ? this.invoiceData[0].id : "",
					};
					api.prescriptioninfo(para).then((res) => {
						uni.showToast({
							title: "操作成功",
							icon: "success",
							mask: true,
						});
						setTimeout(() => {
							uni.switchTab({
								url: "/pages/home/index",
							});
						}, 1000);
					});
				}
				// app.getUserInfo()
				//图片上传之前需要id
				// var that = this;
				// if (this.isOpen != '1' && this.isPrescription != '1') {
				// 	if (!this.buyerName) {
				// 		uni.showToast({
				// 			title: '请输入用药人姓名',
				// 			icon: 'none',
				// 			duration: 1500
				// 		});
				// 	} else if (!this.gender) {
				// 		uni.showToast({
				// 			title: '请选择性别',
				// 			icon: 'none',
				// 			duration: 1500
				// 		});
				// 	} else if (!/^\d{1,}$/.test(this.buyerCount)) {
				// 		uni.showToast({
				// 			title: '处方付数请输入纯数字',
				// 			icon: 'none',
				// 			duration: 1500
				// 		});
				// 	} else if (this.buyerCount < 1) {
				// 		uni.showToast({
				// 			title: '请选择您的处方付数',
				// 			icon: 'none',
				// 			duration: 1500
				// 		});
				// 	} else if (this.buyerCount > 10000) {
				// 		uni.showToast({
				// 			title: '付数超出限制（10000付）',
				// 			icon: 'none',
				// 			duration: 1500
				// 		});
				// 	} else if (this.uploaderList.length == 0) {
				// 		uni.showToast({
				// 			title: '请选择您要上传的图片',
				// 			icon: 'none',
				// 			duration: 1500
				// 		});
				// 	} else if (this.transType != 0 && !this.userAddress.id) {
				// 		uni.showToast({
				// 			title: '请选择您的邮寄地址',
				// 			icon: 'none',
				// 			duration: 1500
				// 		});
				// 	} else {
				// 		let orderImgUrl = that.uploaderList;
				// 		let imgArr = [];
				// 		let imgUrl = '';
				// 		orderImgUrl.map(function(elem) {
				// 			if (elem.indexOf("tmp") != -1) {
				// 				imgArr.push(elem);
				// 			} else if (elem.indexOf("btsyd") != -1) {
				// 				if (imgUrl.length == 0) {
				// 					imgUrl = elem;
				// 				} else {
				// 					imgUrl = imgUrl + ';' + elem;
				// 				}
				// 			}
				// 		});
				// 		that.uploadImgUrl = imgUrl
				// 		that.imgArr = imgArr
				// 		that.loading = true
				// api.wxgetSnowflake().then(res => {
				// 	if (res.code == 0) {
				// 		that.imageCode = res.data
				// 		uni.requestSubscribeMessage({
				// 			tmplIds: ['6nJMWMlFxfiWZbwTrHmRbXHRGzHv0n3ozU48Hd9-2Mo'],
				// 			// 此处可填写多个模板 ID，但低版本微信不兼容只能授权一个
				// 			success(res) {
				// 				//#ifdef H5
				// 				that.submitPresImg();
				// 				//#endif
				// 				//#ifdef MP
				// 				if (that.imgArr.length > 0) {
				// 					that.submitPresImg();
				// 				} else {
				// 					that.submitPres();
				// 				}
				// 				//#endif
				// 				console.log('已授权接收订阅消息');
				// 			}
				// 		});
				// 	} else {
				// 		that.loading = false
				// 	}
				// }).catch(() => {
				// 	that.loading = false
				// });
				// }
				// } else {
				// 	let orderImgUrl = that.uploaderList;
				// 	let imgArr = [];
				// 	let imgUrl = '';
				// 	orderImgUrl.map(function(elem) {
				// 		if (elem.indexOf("tmp") != -1) {
				// 			imgArr.push(elem);
				// 		} else if (elem.indexOf("btsyd") != -1) {
				// 			if (imgUrl.length == 0) {
				// 				imgUrl = elem;
				// 			} else {
				// 				imgUrl = imgUrl + ';' + elem;
				// 			}
				// 		}
				// 	});
				// 	that.uploadImgUrl = imgUrl
				// 	that.imgArr = imgArr
				// 	that.loading = true
				// 	api.wxgetSnowflake().then(res => {
				// 		if (res.code == 0) {
				// 			that.imageCode = res.data
				// 			uni.requestSubscribeMessage({
				// 				tmplIds: ['6nJMWMlFxfiWZbwTrHmRbXHRGzHv0n3ozU48Hd9-2Mo'],
				// 				// 此处可填写多个模板 ID，但低版本微信不兼容只能授权一个
				// 				success(res) {
				// 					//#ifdef H5
				// 					that.submitPresImg();
				// 					//#endif
				// 					//#ifdef MP
				// 					if (that.imgArr.length > 0) {
				// 						that.submitPresImg();
				// 					} else {
				// 						that.submitPres();
				// 					}
				// 					//#endif
				// 					console.log('已授权接收订阅消息');
				// 				}
				// 			});
				// 		} else {
				// 			that.loading = false
				// 		}
				// 	}).catch(() => {
				// 		that.loading = false
				// 	});
				// }
			},

			// submitPresImg() {
			// 	//图片上传提交
			// 	uni.showLoading({
			// 		title: "上传中...",
			// 		mask: true,
			// 	});
			// 	let url = "/mallapi/api/ma/prescriptions/preUpLoad";
			// 	let _url = __config.basePath + url;
			// 	//#ifdef H5
			// 	_url = __config.basePath + url;
			// 	var picUrl = this.uploaderListH5.length;
			// 	var pathList = this.uploaderListH5;
			// 	var that = this,
			// 		i = pathList.i ? pathList.i : 0,
			// 		success = pathList.success ? pathList.success : 0,
			// 		fail = pathList.fail ? pathList.fail : 0;
			// 	//#endif
			// 	//#ifdef MP
			// 	var picUrl = this.imgArr.length;
			// 	var pathList = this.imgArr;
			// 	var that = this,
			// 		i = pathList.i ? pathList.i : 0,
			// 		success = pathList.success ? pathList.success : 0,
			// 		fail = pathList.fail ? pathList.fail : 0;
			// 	//#endif
			// 	uni.uploadFile({
			// 		url: _url,
			// 		//H5
			// 		// header: {
			// 		// 	'client-type': util.isWeiXinBrowser() ? 'H5-WX' : 'H5', //客户端类型普通H5或微信H5
			// 		// 	'tenant-id': getApp().globalData.tenantId,
			// 		// 	'app-id': getApp().globalData.appId ? getApp().globalData.appId : '', //微信h5有appId
			// 		// 	'third-session' : uni.getStorageSync('third_session ')
			// 		// },
			// 		// files: [{
			// 		// 	name: 'file',
			// 		// 	file: pathList[i].tempFiles[0],
			// 		// 	uri: pathList[i].tempFilePaths[0]
			// 		// }],
			// 		//
			// 		filePath: pathList[i],
			// 		name: "fileImg",
			// 		header: {
			// 			"app-id": "wxce3d675f6e1728e4",
			// 			"third-session": uni.getStorageSync("third_session"),
			// 		},
			// 		formData: {
			// 			id: this.imageCode,
			// 		},
			// 		success: (res) => {
			// 			console.log(`success`, res);
			// 			try {
			// 				var st = JSON.parse(res.data);
			// 				success++;
			// 				if (that.uploadImgUrl.length == "") {
			// 					that.uploadImgUrl = st.data;
			// 				} else {
			// 					var str = that.uploadImgUrl + ";" + st.data;
			// 					that.uploadImgUrl = str;
			// 				}
			// 			} catch (error) {
			// 				fail++;
			// 			}
			// 		},
			// 		fail: (res) => {
			// 			console.log(`fail`, res);
			// 			fail++;
			// 			console.log("fail:" + i + "fail:" + fail);
			// 		},
			// 		complete: (res) => {
			// 			i++;
			// 			if (i == pathList.length) {
			// 				//当图片传完时，停止调用
			// 				if (fail !== 0) {
			// 					that.loading = false;
			// 					uni.hideLoading();
			// 					uni.showModal({
			// 						title: "提示",
			// 						content: "上传失败！",
			// 					});
			// 					return;
			// 				} else {
			// 					that.loading = false;
			// 					that.submitPres();
			// 				}
			// 			} else {
			// 				//若图片还没有传完，则继续调用函数
			// 				pathList.i = i;
			// 				pathList.success = success;
			// 				pathList.fail = fail;
			// 				that.submitPresImg();
			// 			}
			// 		},
			// 	});
			// },
			submitPres() {
				// return
				//图片和信息一起提交
				let userInfo = this.userInfo;
				let phone = null;
				let buyerName = this.buyerName;
				let isInvoice = 0;
				let title = null;
				let identcode = null;

				if (this.invoiceData.length > 0) {
					isInvoice = 1;
					title = this.invoiceData[0].rise;
					identcode = this.invoiceData[0].tax;
				}
				if (this.transType == 0) {
					this.userAddress.telNum = null;
					this.userAddress.id = null;
					this.userAddress.provinceName = null;
					this.userAddress.cityName = null;
					this.userAddress.countyName = null;
					this.userAddress.detailInfo = null;
					phone = userInfo.phone;
				} else {
					phone = this.userAddress.telNum;
				}
				var that = this;
				var postData = {
					// appType: 'MA',
					comefrom: 3,
					// 邮费
					// transFee:'10',
					buyerName: buyerName,
					//购买人姓名
					buyerPhone: phone,
					buyerGender: userInfo.sex,
					//购买人性别(1:男,2:女)
					gender: this.gender === "男" ? 1 : 2,
					buyerBirthday: userInfo.birthday,
					//购买人年龄
					customerId: userInfo.mallUserId,
					openId: userInfo.phone,
					addressId: this.userAddress.id,
					//地址id
					province: this.userAddress.provinceName,

					//省
					city: this.userAddress.cityName,
					//市
					county: this.userAddress.countyName,
					//区
					buyerAddress: this.userAddress.detailInfo,
					//地址
					buyerCount: this.buyerCount,
					//数量
					buyerIsdj: this.buyerIsdj,
					tjtype: this.tjtype, //是否颗粒剂
					//是否代煎(0:否,1:是)
					buyerIsjg: this.buyerIsjg,
					//是否加工(0:否,1:是)
					logisticsType: this.transType,
					// 取药方式0自取
					picUrls: this.uploadImgUrl,
					//图片路径";"分割
					buyerMemo: this.memo,
					//备注
					isInvoice: isInvoice,
					// 是否开票
					title: title,
					// 发票抬头
					identcode: identcode,
					// 税号
					id: this.imageCode, //上传图片携带的ID
					organId: "1", //公司ID
					presFrom: 0, //上传方式
				};
				console.log("确认提交参数==============", postData);
				let url = "/mallapi/api/ma/prescriptions/prescriptionUpLoad";
				let _url = __config.basePath + url;
				uni.request({
					url: _url,
					data: postData,
					header: {
						"app-id": "wxce3d675f6e1728e4",
						"client-type": "MA",
						"third-session": uni.getStorageSync("third_session"),
					},
					method: "POST",
					dataType: "json",
					responseType: "text",
					success: (res) => {
						that.setData = false;
						if (res.data.code == 1) {
							uni.hideLoading();
							uni.showModal({
								title: "提示",
								content: res.data.msg,
							});
						} else if (res.data.code == 60001) {
							uni.showToast({
								title: "登录超时，请重新登录",
								icon: "none",
								duration: 2000,
							});
						} else {
							that.uploaderList = [];
							uni.hideLoading();
							uni.redirectTo({
								url: "/pages/order/order-detail/index?id=" + res.data.data,
							});
						}
					},
					fail: (res) => {},
					complete: (res) => {
						// console.log(res)
						that.loading = false;
					},
				});
			},

			getDefaultAddress() {
				//获取默认收货地址
				api.getDefaultAddress().then((res) => {
					let data = res.data;
					if (data) {
						this.userAddress = data;
					}
				});
			},
			setSelfAddress(item) {
				this.addressObj = item
				console.log(this.addressObj, 'this.addressObj');
			},

			jumpToAddressList(i) {
				if (i == 2) {
					uni.navigateTo({
						url: '/pages/self-lifting/self-lifting'
					})
					return
				}
				//跳转到收货地址页面
				uni.navigateTo({
					url: "/pages/user/user-address/list/index?select=true",
				});
			},

			successTipHide() {
				//处方上传成功后的提示
				this.successTip = false;
				this.shareShowFun();
			},
			shareShowFun() {
				this.shareShow = show;
			},
		},
	};
</script>
<style>
	@import "./index.css";
</style>